﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Animation;

namespace JY.Wpf.Controls.Controls.TransitionPresenter
{
    public class TransitionStoryboard
    {
        /// <summary>
        /// 反序列化动画效果
        /// </summary>
        /// <param name="key">动画效果名称</param>
        /// <returns>动画效果和动画时间</returns>
        public static TranStoryboards TranSBDerialize(string key)
        {
            if (TranSBDictionary.Count > 0)
            {
                TranStoryboards t = TranSBDictionary[key];
                return t;
            }
            else
            {
                getTran();
                return TranSBDictionary[key];
            }
        }
        static Dictionary<string, TranStoryboards> TranSBDictionary = new Dictionary<string, TranStoryboards>();

        /// <summary>
        /// 序列化动画效果
        /// </summary>
        static void getTran()
        {
            ResourceDictionary styleDictionary = new ResourceDictionary();
            styleDictionary.Source = new Uri("pack://Application:,,,/JY.Wpf.Controls;component/TransitionPresenter/TranSBDictionary.xaml");

            #region 添加Base
            Transition tranBase = new Transition();
            TranStoryboards tBase = new TranStoryboards();
            tBase.NewDuration = TimeSpan.FromSeconds(0.0);
            tBase.Tran = tranBase;
            TranSBDictionary.Add("Base", tBase);
            #endregion

            #region 添加Fade
            FadeTransition tranFade = new FadeTransition();
            TranStoryboards tFade = new TranStoryboards();
            tFade.NewDuration = TimeSpan.FromSeconds(0.5);
            tranFade.Duration = tFade.NewDuration;
            tFade.Tran = tranFade;
            TranSBDictionary.Add("Fade", tFade);
            #endregion

            #region 添加FadeWipe2
            StoryboardTransition tranFadeWipe2 = new StoryboardTransition();
            TranStoryboards tFadeWipe2 = new TranStoryboards();
            Storyboard sbFadeWipe2 = new Storyboard();
            sbFadeWipe2 = (Storyboard)styleDictionary["FadeWipe2NewStorboard"];
            tFadeWipe2.NewStoryboard = sbFadeWipe2;
            tranFadeWipe2.NewContentStoryboard = sbFadeWipe2;

            tFadeWipe2.Tran = tranFadeWipe2;
            tFadeWipe2.NewDuration = TimeSpan.FromSeconds(0.7);
            TranSBDictionary.Add("FadeWipe2", tFadeWipe2);
            #endregion

            #region 添加Star
            //AMDVideoShow.Utility.Transition.StoryboardTransition tranStar = new StoryboardTransition();
            //TranStoryboards tStar = new TranStoryboards();
            //Style styleStar = new Style();
            //styleStar = (Style)styleDictionary["StarNewStyle"];
            //Storyboard sbStar = new Storyboard();
            //sbStar = (Storyboard)styleDictionary["StarNewStoryboard"];

            //tStar.NewDuration = TimeSpan.FromSeconds(0.7);
            //tStar.NewStoryboard = sbStar;
            //tStar.NewStyle = styleStar;
            //tranStar.NewContentStoryboard = sbStar;
            //tranStar.NewContentStyle = styleStar;
            //tStar.Tran = tranStar;
            //TranSBDictionary.Add("Star", tStar); 
            #endregion

            //
            #region 添加Melt
            StoryboardTransition tranMelt = new StoryboardTransition();
            TranStoryboards tMelt = new TranStoryboards();
            Style styleMelt = new Style();
            styleMelt = (Style)styleDictionary["MeltNewStyle"];
            Storyboard sbMelt = new Storyboard();
            sbMelt = (Storyboard)styleDictionary["MeltNewStoryboard"];

            tMelt.NewDuration = TimeSpan.FromSeconds(0.7);
            tMelt.NewStoryboard = sbMelt;
            tMelt.NewStyle = styleMelt;
            tranMelt.NewContentStoryboard = sbMelt;
            tranMelt.NewContentStyle = styleMelt;
            tMelt.Tran = tranMelt;
            TranSBDictionary.Add("Melt", tMelt);
            #endregion

            #region 添加HorizontalWipe
            StoryboardTransition tranHorizontalWipe = new StoryboardTransition();
            TranStoryboards tHorizontalWipe = new TranStoryboards();
            Style styleHorizontalWipe=(Style)styleDictionary["HorizontalWipeNewStyle"];
            Storyboard sbHorizontalWipe =  (Storyboard)styleDictionary["HorizontalWipeNewStoryboard"];

            tHorizontalWipe.NewDuration = TimeSpan.FromSeconds(0.7);
            tHorizontalWipe.NewStoryboard = sbHorizontalWipe;
            tHorizontalWipe.NewStyle = styleHorizontalWipe;
            tranHorizontalWipe.NewContentStoryboard = sbHorizontalWipe;
            tranHorizontalWipe.NewContentStyle = styleHorizontalWipe;
            tHorizontalWipe.Tran = tranHorizontalWipe;
            TranSBDictionary.Add("HorizontalWipe", tHorizontalWipe);
            #endregion

            #region 添加HorizontalWipe2
            StoryboardTransition tranHorizontalWipe2 = new StoryboardTransition();
            TranStoryboards tHorizontalWipe2 = new TranStoryboards();
            Style styleHorizontalWipe2 = (Style)styleDictionary["HorizontalWipeNewStyle2"];
            Storyboard sbHorizontalWipe2 =  (Storyboard)styleDictionary["HorizontalWipeNewStoryboard2"];

            tHorizontalWipe2.NewDuration = TimeSpan.FromSeconds(0.7);
            tHorizontalWipe2.NewStoryboard = sbHorizontalWipe2;
            tHorizontalWipe2.NewStyle = styleHorizontalWipe2;
            tranHorizontalWipe2.NewContentStoryboard = sbHorizontalWipe2;
            tranHorizontalWipe2.NewContentStyle = styleHorizontalWipe2;
            tHorizontalWipe2.Tran = tranHorizontalWipe2;
            TranSBDictionary.Add("HorizontalWipe2", tHorizontalWipe2);
            #endregion

            #region 添加VerticalWipe
            StoryboardTransition tranVerticalWipe = new StoryboardTransition();
            TranStoryboards tVerticalWipe = new TranStoryboards();
            Style styleVerticalWipe = new Style();
            styleVerticalWipe = (Style)styleDictionary["VerticalWipeNewStyle"];
            Storyboard sbVerticalWipe = new Storyboard();
            sbVerticalWipe = (Storyboard)styleDictionary["VerticalWipeNewStoryboard"];

            tVerticalWipe.NewDuration = TimeSpan.FromSeconds(0.7);
            tVerticalWipe.NewStoryboard = sbVerticalWipe;
            tVerticalWipe.NewStyle = styleVerticalWipe;
            tranVerticalWipe.NewContentStoryboard = sbVerticalWipe;
            tranVerticalWipe.NewContentStyle = styleVerticalWipe;
            tVerticalWipe.Tran = tranVerticalWipe;
            TranSBDictionary.Add("VerticalWipe", tVerticalWipe);
            #endregion

            #region 添加DiagonalWipe
            StoryboardTransition tranDiagonalWipe = new StoryboardTransition();
            TranStoryboards tDiagonalWipe = new TranStoryboards();
            Style styleDiagonalWipe = new Style();
            styleDiagonalWipe = (Style)styleDictionary["DiagonalWipeNewStyle"];
            Storyboard sbDiagonalWipe = new Storyboard();
            sbDiagonalWipe = (Storyboard)styleDictionary["DiagonalWipeNewStoryboard"];

            tDiagonalWipe.NewDuration = TimeSpan.FromSeconds(0.7);
            tDiagonalWipe.NewStoryboard = sbDiagonalWipe;
            tDiagonalWipe.NewStyle = styleDiagonalWipe;
            tranDiagonalWipe.NewContentStoryboard = sbDiagonalWipe;
            tranDiagonalWipe.NewContentStyle = styleDiagonalWipe;
            tDiagonalWipe.Tran = tranDiagonalWipe;
            TranSBDictionary.Add("DiagonalWipe", tDiagonalWipe);
            #endregion
            
            #region 添加RotateWipe
            StoryboardTransition tranRotateWipe = new StoryboardTransition();
            TranStoryboards tRotateWipe = new TranStoryboards();
            Style styleRotateWipe = new Style();
            styleRotateWipe = (Style)styleDictionary["RotateWipeNewStyle"];
            Storyboard sbRotateWipe = new Storyboard();
            sbRotateWipe = (Storyboard)styleDictionary["RotateWipeNewStoryboard"];

            tRotateWipe.NewDuration = TimeSpan.FromSeconds(0.7);
            tRotateWipe.NewStoryboard = sbRotateWipe;
            tRotateWipe.NewStyle = styleRotateWipe;
            tranRotateWipe.NewContentStoryboard = sbRotateWipe;
            tranRotateWipe.NewContentStyle = styleRotateWipe;
            tRotateWipe.Tran = tranRotateWipe;
            TranSBDictionary.Add("RotateWipe", tRotateWipe);
            #endregion
            
            #region 添加DoubleRotateWipe
            StoryboardTransition tranDoubleRotateWipe = new StoryboardTransition();
            TranStoryboards tDoubleRotateWipe = new TranStoryboards();
            Style styleDoubleRotateWipe = new Style();
            styleDoubleRotateWipe = (Style)styleDictionary["DoubleRotateWipeNewStyle"];
            Storyboard sbDoubleRotateWipe = new Storyboard();
            sbDoubleRotateWipe = (Storyboard)styleDictionary["DoubleRotateWipeNewStoryboard"];

            tDoubleRotateWipe.NewDuration = TimeSpan.FromSeconds(0.7);
            tDoubleRotateWipe.NewStoryboard = sbDoubleRotateWipe;
            tDoubleRotateWipe.NewStyle = styleDoubleRotateWipe;
            tranDoubleRotateWipe.NewContentStoryboard = sbDoubleRotateWipe;
            tranDoubleRotateWipe.NewContentStyle = styleDoubleRotateWipe;
            tDoubleRotateWipe.Tran = tranDoubleRotateWipe;
            TranSBDictionary.Add("DoubleRotateWipe", tDoubleRotateWipe);
            #endregion

            #region 添加VerticalBlinds
            StoryboardTransition tranVerticalBlinds = new StoryboardTransition();
            TranStoryboards tVerticalBlinds = new TranStoryboards();
            Style styleVerticalBlinds = new Style();
            styleVerticalBlinds = (Style)styleDictionary["VerticalBlindsNewStyle"];
            Storyboard sbVerticalBlinds = new Storyboard();
            sbVerticalBlinds = (Storyboard)styleDictionary["VerticalBlindsNewStoryboard"];

            tVerticalBlinds.NewDuration = TimeSpan.FromSeconds(0.7);
            tVerticalBlinds.NewStoryboard = sbVerticalBlinds;
            tVerticalBlinds.NewStyle = styleVerticalBlinds;
            tranVerticalBlinds.NewContentStoryboard = sbVerticalBlinds;
            tranVerticalBlinds.NewContentStyle = styleVerticalBlinds;
            tVerticalBlinds.Tran = tranVerticalBlinds;
            TranSBDictionary.Add("VerticalBlinds", tVerticalBlinds);
            #endregion

            #region 添加HorizontalBlinds
            StoryboardTransition tranHorizontalBlinds = new StoryboardTransition();
            TranStoryboards tHorizontalBlinds = new TranStoryboards();
            Style styleHorizontalBlinds = new Style();
            styleHorizontalBlinds = (Style)styleDictionary["HorizontalBlindsNewStyle"];
            Storyboard sbHorizontalBlinds = new Storyboard();
            sbHorizontalBlinds = (Storyboard)styleDictionary["HorizontalBlindsNewStoryboard"];

            tHorizontalBlinds.NewDuration = TimeSpan.FromSeconds(0.7);
            tHorizontalBlinds.NewStoryboard = sbHorizontalBlinds;
            tHorizontalBlinds.NewStyle = styleHorizontalBlinds;
            tranHorizontalBlinds.NewContentStoryboard = sbHorizontalBlinds;
            tranHorizontalBlinds.NewContentStyle = styleHorizontalBlinds;
            tHorizontalBlinds.Tran = tranHorizontalBlinds;
            TranSBDictionary.Add("HorizontalBlinds", tHorizontalBlinds);
            #endregion

            #region 添加Diamonds
            StoryboardTransition tranDiamonds = new StoryboardTransition();
            TranStoryboards tDiamonds = new TranStoryboards();
            Style styleDiamonds = new Style();
            styleDiamonds = (Style)styleDictionary["DiamondsNewStyle"];
            Storyboard sbDiamonds = new Storyboard();
            sbDiamonds = (Storyboard)styleDictionary["DiamondsNewStoryboard"];

            tDiamonds.NewDuration = TimeSpan.FromSeconds(0.7);
            tDiamonds.NewStoryboard = sbDiamonds;
            tDiamonds.NewStyle = styleDiamonds;
            tranDiamonds.NewContentStoryboard = sbDiamonds;
            tranDiamonds.NewContentStyle = styleDiamonds;
            tDiamonds.Tran = tranDiamonds;
            TranSBDictionary.Add("Diamonds", tDiamonds);
            #endregion

            #region 添加Checkerboard
            StoryboardTransition tranCheckerboard = new StoryboardTransition();
            TranStoryboards tCheckerboard = new TranStoryboards();
            Style styleCheckerboard = new Style();
            styleCheckerboard = (Style)styleDictionary["CheckerboardNewStyle"];
            Storyboard sbCheckerboard = new Storyboard();
            sbCheckerboard = (Storyboard)styleDictionary["CheckerboardNewStoryboard"];

            tCheckerboard.NewDuration = TimeSpan.FromSeconds(0.7);
            tCheckerboard.NewStoryboard = sbCheckerboard;
            tCheckerboard.NewStyle = styleCheckerboard;
            tranCheckerboard.NewContentStoryboard = sbCheckerboard;
            tranCheckerboard.NewContentStyle = styleCheckerboard;
            tCheckerboard.Tran = tranCheckerboard;
            TranSBDictionary.Add("Checkerboard", tCheckerboard);
            #endregion

            #region 添加Roll
            StoryboardTransition tranRoll = new StoryboardTransition();
            TranStoryboards tRoll = new TranStoryboards();
            Style styleRoll = new Style();
            styleRoll = (Style)styleDictionary["RollOldStyle"];
            Storyboard sbRoll = new Storyboard();
            sbRoll = (Storyboard)styleDictionary["RollOldStoryboard"];

            tRoll.OldDuration = TimeSpan.FromSeconds(0.7);
            tRoll.OldStoryboard = sbRoll;
            tRoll.OldStyle = styleRoll;
            tranRoll.OldContentStoryboard = sbRoll;
            tranRoll.OldContentStyle = styleRoll;
            tRoll.Tran = tranRoll;
            TranSBDictionary.Add("Roll", tRoll);
            #endregion

            #region 添加Dots
            StoryboardTransition tranDots = new StoryboardTransition();
            TranStoryboards tDots = new TranStoryboards();
            Style styleDots = new Style();
            styleDots = (Style)styleDictionary["DotsNewStyle"];
            Storyboard sbDots = new Storyboard();
            sbDots = (Storyboard)styleDictionary["DotsNewStoryboard"];

            tDots.NewDuration = TimeSpan.FromSeconds(0.7);
            tDots.NewStoryboard = sbDots;
            tDots.NewStyle = styleDots;
            tranDots.NewContentStoryboard = sbDots;
            tranDots.NewContentStyle = styleDots;
            tDots.Tran = tranDots;
            TranSBDictionary.Add("Dots", tDots); 
            #endregion

            //添加FadeAndGrow
            #region 添加FadeAndGrow
            
            StoryboardTransition tranFadeAndGrow = new StoryboardTransition();
            TranStoryboards tFadeAndGrow = new TranStoryboards();
            Style styleNewFadeAndGrow = new Style();
            styleNewFadeAndGrow = (Style)styleDictionary["FadeAndGrowNewStyle"];
            Storyboard sbNewFadeAndGrow = new Storyboard();
            sbNewFadeAndGrow = (Storyboard)styleDictionary["FadeAndGrowNewStoryboard"];

            Style styleOldFadeAndGrow = new Style();
            styleOldFadeAndGrow = (Style)styleDictionary["FadeAndGrowOldStyle"];
            Storyboard sbOldFadeAndGrow = new Storyboard();
            sbOldFadeAndGrow = (Storyboard)styleDictionary["FadeAndGrowOldStoryboard"];

            tFadeAndGrow.NewDuration = TimeSpan.FromSeconds(0.7);
            tFadeAndGrow.OldDuration = TimeSpan.FromSeconds(0.7);

            tFadeAndGrow.NewStoryboard = sbNewFadeAndGrow;
            tFadeAndGrow.OldStoryboard = sbOldFadeAndGrow;

            tFadeAndGrow.NewStyle = styleNewFadeAndGrow;
            tFadeAndGrow.OldStyle = styleOldFadeAndGrow;

            tranFadeAndGrow.NewContentStoryboard = sbNewFadeAndGrow;
            tranFadeAndGrow.OldContentStoryboard = sbOldFadeAndGrow;

            tranFadeAndGrow.NewContentStyle = styleNewFadeAndGrow;
            tranFadeAndGrow.OldContentStyle = styleOldFadeAndGrow;
            tFadeAndGrow.Tran = tranFadeAndGrow;
            TranSBDictionary.Add("FadeAndGrow", tFadeAndGrow);
            #endregion

            #region 添加Translate2DTransition
            TranslateTransition tranTranslate2DTransition = new TranslateTransition();
            TranStoryboards tTranslate2DTransition = new TranStoryboards();
            tTranslate2DTransition.NewDuration = TimeSpan.FromSeconds(0.5);

            tranTranslate2DTransition.Duration = tTranslate2DTransition.NewDuration;
            tranTranslate2DTransition.StartPoint = new Point(-1.0, 0.0); 

            tTranslate2DTransition.Tran = tranTranslate2DTransition;
            TranSBDictionary.Add("Translate2DTransition", tTranslate2DTransition);
            #endregion

            #region 添加Flip3D
            FlipTransition tranFlip3D = new FlipTransition();
            TranStoryboards tFlip3D = new TranStoryboards();
            tFlip3D.NewDuration = TimeSpan.FromSeconds(0.5);

            tranFlip3D.Duration = tFlip3D.NewDuration;

            tFlip3D.Tran = tranFlip3D;
            TranSBDictionary.Add("Flip3D", tFlip3D);
            #endregion

            #region 添加Door3D
            DoorTransition tranDoor3D = new DoorTransition();
            TranStoryboards tDoor3D = new TranStoryboards();
            tDoor3D.NewDuration = TimeSpan.FromSeconds(0.5);

            tranDoor3D.Duration = tDoor3D.NewDuration;
            tranDoor3D.FieldOfView = 40.0;

            tDoor3D.Tran = tranDoor3D;
            TranSBDictionary.Add("Door3D", tDoor3D);
            #endregion

            #region 添加Rotate3D
            RotateTransition tranRotate3D = new RotateTransition();
            TranStoryboards tRotate3D = new TranStoryboards();
            tRotate3D.NewDuration = TimeSpan.FromSeconds(0.5);

            tranRotate3D.Duration = tRotate3D.NewDuration;
            tranRotate3D.FieldOfView = 40.0;

            tRotate3D.Tran = tranRotate3D;
            TranSBDictionary.Add("Rotate3D", tRotate3D);
            #endregion

            #region 添加Spin3D
            RotateTransition tranSpin3D = new RotateTransition();
            TranStoryboards tSpin3D = new TranStoryboards();
            tSpin3D.NewDuration = TimeSpan.FromSeconds(0.75);

            tranSpin3D.Duration = tSpin3D.NewDuration;
            tranSpin3D.FieldOfView = 40.0;
            tranSpin3D.Angle = 0.0;
            tranSpin3D.Direction=RotateDirection.Up;
            tranSpin3D.Contained=true;
            tSpin3D.Tran = tranSpin3D;
            TranSBDictionary.Add("Spin3D", tSpin3D);
            #endregion

            #region 添加Explosion3D
            ExplosionTransition tranExplosion3D = new ExplosionTransition();
            TranStoryboards tExplosion3D = new TranStoryboards();
            tExplosion3D.NewDuration = TimeSpan.FromSeconds(0.0);

            tExplosion3D.Tran = tranExplosion3D;
            TranSBDictionary.Add("Explosion3D", tExplosion3D);
            #endregion

            #region 添加Cloth
            ClothTransition tranCloth = new ClothTransition();
            TranStoryboards tCloth = new TranStoryboards();
            tCloth.NewDuration = TimeSpan.FromSeconds(0.0);

            tCloth.Tran = tranCloth;
            TranSBDictionary.Add("Cloth", tCloth);
            #endregion

            #region 添加Page
            PageTransition tranPage = new PageTransition();
            TranStoryboards tPage = new TranStoryboards();
            tPage.NewDuration = TimeSpan.FromSeconds(0.75);

            tranPage.FieldOfView = 10.0;
            tranPage.ClipToBounds = true;

            tPage.Tran = tranPage;
            TranSBDictionary.Add("Page", tPage);
            #endregion
        }
    
    }

    /// <summary>
    /// 动画
    /// </summary>
    public class TranStoryboards
    {
        private Duration _oldDuration;
        private Duration _newDuration;

        private Storyboard _oldStoryboard;
        private Storyboard _newStoryboard;

        private Style _oldStyle;
        private Style _newStyle;

        private Transition _tran;

        public Transition Tran
        {
            get { return _tran; }
            set { _tran = value; }
        }

        public Duration OldDuration
        {
            get { return _oldDuration; }
            set { _oldDuration = value; }
        }
        public Duration NewDuration
        {
            get { return _newDuration; }
            set { _newDuration = value; }
        }

        public Storyboard OldStoryboard
        {
            get { return _oldStoryboard; }
            set { _oldStoryboard = value; }
        }
        public Storyboard NewStoryboard
        {
            get { return _newStoryboard; }
            set { _newStoryboard = value; }
        }


        public Style OldStyle
        {
            get { return _oldStyle; }
            set { _oldStyle = value; }
        }
        public Style NewStyle
        {
            get { return _newStyle; }
            set { _newStyle = value; }
        }
    }
}
